package org.spring.springboot.dao;
import java.util.Map;

import org.spring.springboot.domain.City;
public class CitySqlProvider {
    private final static String TABLE_NAME = "city";
    public String find(Map<String, Object> params) {
    	City city=(City)params.get("city");
    	CustomSQL sql=new CustomSQL()
    			.SELECT("id,province_id,city_name,description")
    			.FROM(TABLE_NAME)
    			.WHERE_IF("id=#{city.id}", city.getId()!= null)
    			.WHERE_IF("city_name=#{city.cityName}", city.getCityName()!= null)
    			.WHERE_IF("province_id=#{city.province.id}", city.getProvince()!= null)
    			.WHERE_IF("description=#{city.description}", city.getDescription()!= null);
    	return sql.toString();
    }
    
    public String add(Map<String, Object> params) {
    	City city=(City)params.get("city");
    	CustomSQL sql=new CustomSQL()
    			.INSERT_INTO(TABLE_NAME)
    			.VALUES_IF("city_name", "#{city.cityName}",city.getCityName()!= null)
    			.VALUES_IF("province_id", "#{city.province.id}",city.getProvince()!= null)
    			.VALUES_IF("description", "#{city.description}",city.getCityName()!= null);
    	return sql.toString();		
    }
   
 
}
